package com.nt.oam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.nt.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nt.common.annotation.Log;
import com.nt.common.core.controller.BaseController;
import com.nt.common.core.domain.AjaxResult;
import com.nt.common.enums.BusinessType;
import com.nt.oam.domain.AntDatabaseAsset;
import com.nt.oam.service.IAntDatabaseAssetService;
import com.nt.common.utils.poi.ExcelUtil;
import com.nt.common.core.page.TableDataInfo;

/**
 * 数据库资产Controller
 *
 * @author JZFeng
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/oam/database")
public class AntDatabaseAssetController extends BaseController {
    @Autowired
    private IAntDatabaseAssetService antDatabaseAssetService;

    /**
     * 查询数据库资产列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:database:list')")
    @GetMapping("/list")
    public TableDataInfo list(AntDatabaseAsset antDatabaseAsset) {
        startPage();
        List<AntDatabaseAsset> list = antDatabaseAssetService.selectAntDatabaseAssetList(antDatabaseAsset);
        return getDataTable(list);
    }

    /**
     * 导出数据库资产列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:database:export')")
    @Log(title = "数据库资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AntDatabaseAsset antDatabaseAsset) {
        List<AntDatabaseAsset> list = antDatabaseAssetService.selectAntDatabaseAssetList(antDatabaseAsset);
        ExcelUtil<AntDatabaseAsset> util = new ExcelUtil<AntDatabaseAsset>(AntDatabaseAsset.class);
        util.exportExcel(response, list, "数据库资产数据");
    }

    /**
     * 获取数据库资产详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:database:query')")
    @GetMapping(value = "/{databaseAssetId}")
    public AjaxResult getInfo(@PathVariable("databaseAssetId") Long databaseAssetId) {
        return success(antDatabaseAssetService.selectAntDatabaseAssetByDatabaseAssetId(databaseAssetId));
    }

    /**
     * 新增数据库资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:database:add')")
    @Log(title = "数据库资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AntDatabaseAsset antDatabaseAsset) {
        return toAjax(antDatabaseAssetService.insertAntDatabaseAsset(antDatabaseAsset));
    }

    /**
     * 修改数据库资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:database:edit')")
    @Log(title = "数据库资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AntDatabaseAsset antDatabaseAsset) {
        return toAjax(antDatabaseAssetService.updateAntDatabaseAsset(antDatabaseAsset));
    }

    /**
     * 删除数据库资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:database:remove')")
    @Log(title = "数据库资产", businessType = BusinessType.DELETE)
    @DeleteMapping("/{databaseAssetIds}")
    public AjaxResult remove(@PathVariable Long[] databaseAssetIds) {
        return toAjax(antDatabaseAssetService.deleteAntDatabaseAssetByDatabaseAssetIds(databaseAssetIds));
    }


    /**
     * 非系统----获取数据库资产详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:database:query')")
    @GetMapping(value = "/details/{databaseAssetId}")
    public AjaxResult getDatabaseAssetMessage(@PathVariable("databaseAssetId") Long databaseAssetId) {
        return success(antDatabaseAssetService.selectDatabaseAsset(databaseAssetId));
    }

    /**
     * 获取页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:database:query')")
    @GetMapping(value = "/get/isModify")
    public AjaxResult getDatabaseModify(@RequestParam Long databaseAssetId) {
        return success(antDatabaseAssetService.selectDatabaseModify(databaseAssetId));
    }

    /**
     * 修改页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:database:edit')")
    @Log(title = "数据库资产", businessType = BusinessType.UPDATE)
    @PostMapping("/edit/modify/{databaseAssetId}")
    public AjaxResult editModify(@PathVariable("databaseAssetId") Long databaseAssetId) {
        int isModify = 1;
        return toAjax(antDatabaseAssetService.updateDatabaseModify(databaseAssetId, isModify));
    }
}
